package com.cogent.business.helper;

import java.util.HashMap;

import com.cogent.common.util.MapUtil;
import com.cogent.dao.BussinessQueryHelper;
import com.cogent.dao.facade.BussinessDaoFacade;

public class BussinessDealHelper {

	public static void copyUserInfo(HashMap curMap, HashMap formMap) {
		if(MapUtil.isEmpty(curMap, "id")) {
			curMap.put("creator", MapUtil.getStringValue(formMap, "modifier"));
			curMap.put("credate", MapUtil.getStringValue(formMap, "modifydate"));
		}
		curMap.put("modifier", MapUtil.getStringValue(formMap, "modifier"));
		curMap.put("modifydate", MapUtil.getStringValue(formMap, "modifydate"));
	}
	
	public static String getSerialNum(BussinessDaoFacade bussinessFacade, String prefix, String seqname) {
		String sql = "select " + seqname + ".Nextval as curval from dual";
		HashMap datamap = bussinessFacade.getOneRow(sql);
		String curvalue = MapUtil.getStringValue(datamap, "curval");
		StringBuffer str = new StringBuffer();
		str.append(prefix);
		for(int i=curvalue.length(); i<12; i++)
			str.append("0");
		str.append(curvalue);
		
		return str.toString();
	}
	
	public static HashMap getValueById(String tableName, String id) {
		return BussinessQueryHelper.getValueById(tableName, id);
	}
}
